package com.atstudent.gmall.product.controller;

import com.atstudent.gmall.common.result.Result;
import com.atstudent.gmall.product.entity.BaseAttrInfo;
import com.atstudent.gmall.product.service.BaseAttrInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.web.bind.annotation.*;

import javax.sql.DataSource;
import java.util.List;

/**
 * 平台属性
 * @Author 薛有朋
 * @CreatDate 2024/11/23 20:51
 **/
@RestController
@RequestMapping(value = "/admin/product")
public class BaseAttrInfoController {

    @Autowired
    private BaseAttrInfoService baseAttrInfoService;

    /**
     * 根据分类id获取平台属性
     * @Author 薛有朋
     * @Date 2024/11/23 21:14
     **/
    @GetMapping(value = "/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result<List<BaseAttrInfo>> findBaseAttrInfo(
            @PathVariable(value = "category1Id") Long c1Id ,
            @PathVariable(value = "category2Id") Long c2Id ,
            @PathVariable(value = "category3Id") Long c3Id){
        List<BaseAttrInfo> attrInfoList = baseAttrInfoService.findBaseAttrInfo(c1Id , c2Id , c3Id);
        return Result.ok(attrInfoList);
    }

    /**
     * 添加平台属性
     * @Author 薛有朋
     * @Date 2024/11/24 11:37
     **/
    @PostMapping(value = "/saveAttrInfo")
    public Result saveBaseAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        baseAttrInfoService.saveBaseAttrInfo(baseAttrInfo);
        return Result.ok();
    }
}
